home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / oop_tp55.zip / ROBOT_B.PAS < prev    next >
Pascal/Delphi Source File  |  1990-02-20  |  3KB  |  109 lines

  1. unit Robot_B; { Listing 10-6 }
  2.  
  3. interface
  4.  
  5. uses Graph, Mouse, Crt, RobotSeg, Robot_A;
  6.  
  7. type
  8.  
  9. RobotArm2Ptr = ^RobotArm2;
  10.  
  11. RobotArm2 = object( RobotArm )
  12.             NextSeg : RobotArm2Ptr;
  13.             constructor Init( AnchorX, AnchorY,
  14.                               ArmLen, HandLen : Integer;
  15.                               Position : Degrees;
  16.                               RotStat, DispQ : Boolean;
  17.                               pToNextSeg : pointer);
  18.             procedure MoveAxial( var i : integer ); virtual;
  19.             procedure MoveTo( APoint : Point; DispQ : boolean );
  20.             procedure ShowLimit; virtual;
  21.             end;
  22.  
  23. implementation
  24.  
  25. constructor RobotArm2.Init( AnchorX, AnchorY,
  26.                             ArmLen, HandLen : Integer;
  27.                             Position : Degrees;
  28.                             RotStat, DispQ : Boolean;
  29.                             pToNextSeg : pointer );
  30. begin
  31.      Segment.Init( AnchorX, AnchorY, ArmLen, Position, RotStat );
  32.      NextSeg := pToNextSeg;
  33.      if NextSeg <> nil then
  34.         NextSeg^.Init( BusyEnd.X, BusyEnd.Y, HandLen, 0,
  35.                        Round(Position + 90),
  36.                        false, true, nil );
  37.      if DispQ = true then
  38.         begin
  39.         if NextSeg <> nil then
  40.            begin
  41.            ShowLimit;
  42.            ShowBase;
  43.            end;
  44.         Show;
  45.         end;
  46. end;
  47.  
  48. procedure RobotArm2.MoveAxial( var i : integer );
  49. var D : real;
  50. begin
  51.      Hide;
  52.      if NextSeg <> nil then
  53.         NextSeg^.Hide;
  54.      D := Distance( Anchor, BusyEnd );
  55.      if D-i >= Length then
  56.         D := Length+i;
  57.      if (D <= i) and (Orientation > PI) then
  58.         begin
  59.         Orientation := Orientation - PI;
  60.         D := -(D + i);
  61.         i := -i;
  62.         end
  63.      else
  64.         if D <= i then
  65.            begin
  66.            Orientation := Orientation + PI;
  67.            D := -(D + i);
  68.            i := -i;
  69.            end;
  70.      BusyEnd.X := Round(Anchor.X + cos(Orientation)*(D-i));
  71.      BusyEnd.Y := Round(Anchor.Y - sin(Orientation)*(D-i));
  72.      Show;
  73.      if NextSeg <> nil then
  74.         begin
  75.         NextSeg^.MoveAnchor(BusyEnd.X,BusyEnd.Y);
  76.         NextSeg^.Show;
  77.         end;
  78. end;
  79.  
  80.  
  81. { this insures that all segments (except the first one) will not have
  82.   the base shown with them }
  83. procedure RobotArm2.MoveTo( APoint : Point; DispQ : boolean  );
  84. var D : integer;
  85.     RotDir : integer;
  86.     AxDir  : integer;
  87. begin
  88.      RobotArm.MoveTo( APoint, DispQ );
  89.      if NextSeg <> nil then
  90.         NextSeg^.MoveTo(APoint, false);
  91.      ShowLimit;
  92. end;
  93.  
  94. procedure RobotArm2.ShowLimit;
  95. begin
  96.      if NextSeg <> nil then
  97.         begin
  98.         Graph.SetColor( red);
  99.         with Anchor do
  100.              Rectangle( X - Length,
  101.                         Y - NextSeg^.Length,
  102.                         X + Length,
  103.                         Y + NextSeg^.Length );
  104.         Graph.SetColor(white);
  105.         end;
  106. end;
  107.  
  108.  
  109. end.